/**
 *leetcode 92：反转链表
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */


struct ListNode* reverseBetween(struct ListNode* head, int left, int right){
    int i=1;
    struct ListNode *pvru=(struct ListNode*)malloc(sizeof(struct ListNode));
    pvru->val=-1;
    pvru->next=head;
    struct ListNode*pre=pvru;
    for(int i=0;i<left-1;i++)
    {
        pre=pre->next;//找到反转前一节点
    }
    struct ListNode* p=pre->next;//反转第一个开始节点
    struct ListNode* pm;
    for(int i=0;i<right-left;i++)
    {
        pm=p->next;
        //置换
        p->next=pm->next;//确保反转的第一个元素置后
        //当前元素头插
        pm->next=pre->next;
        pre->next=pm;
        //推进
    }
    return (pvru->next);
}